let blocks = "WWBBBWBBBBBWWBWWWB"
console.log(blocks.length)
var minimumRecolors = function (blocks, k) {
    let right = k - 1 //右边界
    let min = k//定义一个初始值
    let count = 0
    count = arrhowmuschw(blocks, k)
    if(k===blocks.length){
        return count
    }
    while (right + 1 < blocks.length)//定义右边界最终值
    {
        min = Math.min(min, count)//比较取最小值
        if (blocks[right + 1] == 'W')//如果元素为W
        {
            count++
        }
        if (blocks[right - k + 1] == 'W')//如果元素为W
        {
            count--
        }
        right++ //右边界向右移动
        
    }
    return min
};
function arrhowmuschw(blocks, k) {
    let count = 0
    for (let i = 0; i < k; i++) {
        if (blocks[i] == 'W') {
            count++
        }
    }
    return count
}
console.log(minimumRecolors(blocks, 16))